package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/longest-common-prefix/
 * 直接咔咔咔解题
 * author: hongchen.liao
 * date:  2022/8/4
 */
public class _14_Longest_Common_Prefix {

    class Solution {
        public String longestCommonPrefix(String[] strs) {
            int m = strs.length;
            int slen0 = strs[0].length();
            for(int i = 0; i < slen0; i++){
                for(int j = 1; j < m; j++){
                    if(strs[j].length() == i || strs[0].charAt(i) != strs[j].charAt(i)){
                        return strs[0].substring(0, i);
                    }
                }
            }
            return strs[0];
        }
    }


}
